﻿using System;
using Spring.Context.Support;
using Spring.Objects.Factory.Support;

namespace SpringSeries.Core.ObjectDefinitionBuilderFluentInterface
{
    class Program
    {
        static void Main(string[] args)
        {
            GenericApplicationContext _ctx = new GenericApplicationContext();

            _ctx.RegisterObjectDefinition("EngTranslator", ObjectDefinitionBuilder
                                        .RootObjectDefinition(new DefaultObjectDefinitionFactory(), typeof(EnglishToItalianTranslator))
                                        .SetSingleton(true)
                                        .ObjectDefinition);

            _ctx.RegisterObjectDefinition("SpaTranslator", ObjectDefinitionBuilder
                                        .RootObjectDefinition(new DefaultObjectDefinitionFactory(), typeof(SpanishToItalianTranslator))
                                        .SetSingleton(true)
                                        .ObjectDefinition);

            _ctx.RegisterObjectDefinition("ConsoleLog", ObjectDefinitionBuilder
                                        .RootObjectDefinition(new DefaultObjectDefinitionFactory(), typeof(ConsoleTranslatorLog))
                                        .SetSingleton(true)
                                        .ObjectDefinition);


            _ctx.RegisterObjectDefinition("Translator", ObjectDefinitionBuilder
                                        .RootObjectDefinition(new DefaultObjectDefinitionFactory(), typeof(PhraseTranslator))
                                        .AddConstructorArgReference("EngTranslator")
                                        .AddPropertyReference("Log","ConsoleLog")
                                        .SetSingleton(true)
                                        .ObjectDefinition);

            PhraseTranslator _translator = (PhraseTranslator)_ctx.GetObject("Translator");
            Console.WriteLine(_translator.Translate("Hello Spring.NET !!"));
            Console.WriteLine(_translator.Translate("Hola Spring.NET !!"));
            Console.Read();
        }
    }
}
